/* Dynamic type */
def foo = 'foo'
println foo
foo = 1
println foo
foo = [1, 2, 3]
println foo


def fooFunc(foo) {
	println 'The size is ' + foo.size()
}

// running properly.
fooFunc('foo')
fooFunc(['a', 'b', 'c'])
fooFunc(1)
// throw exception.
fooFunc(new Date())

/* ################################################## */
/* Simple reflection */
class Foo {
	def method1() {
		println 'This is the method 1.'
	}

	def method2() {
		println 'This is the method 2.'
		return 'success'
	}
}	

def foo = new Foo()

/* Groovy style */
// Call method1
def methodName = 'method1'
foo."$methodName"()

// Call method2
methodName = 'method2'
println foo."$methodName"()

/* Java style */
import java.lang.reflect.Method

Class fooClass = Foo.class
Method fooMethod1 = fooClass.getMethod('method1', null)
fooMethod1.invoke(foo)